﻿using BJoin.Application.BObject;
using BJoin.Application.Dto;
using BJoin.Application.WebApi.Validation;
using BJoin.Common;
using BJoin.DemoProject.Dtos;
using BJoin.DemoProject.ExtObject;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace BJoin.DemoProject.RW.Webapi.ParamValidations
{
    public class FileExtValidation: AbstractValidator<FileExtObject>
    {
        public FileExtValidation()
        {
            //RuleFor(x => x.A).NotEmpty();
        }
    }
    public class FileAddDtoValidation : AbstractValidator<FileAddDto>
    {
        public FileAddDtoValidation()
        {
            RuleFor(x => x.Code).NotEmpty().WithMessage(string.Format(EnumHelper.GetEnumDescription(MessageEnum.NotEmpty),nameof(FileAddDto.Code)));
            RuleFor(x => x.Name).NotEmpty().WithMessage(string.Format(EnumHelper.GetEnumDescription(MessageEnum.NotEmpty), nameof(FileAddDto.Name)));

            #region Enum Property
            //RuleFor(x => x.Status).NotEmpty().IsInEnum().WithMessage(EnumHelper.GetEnumDescription<MessageEnum>(MessageEnum.NotEnumRange));
            #endregion

            #region include base/navigate property class validation
            //Include(new BaseDtoValidation());
            RuleFor(x => x.Ext).SetValidator(new FileExtValidation());
            #endregion
            #region Special rule
            //RuleFor(x => x).Must(x => int.Parse(x.StartReportYear.ToString() + x.StartReportPeriod.ToString().PadLeft(2, '0')) <= int.Parse(x.EndReportYear.ToString() + x.EndReportPeriod.ToString().PadLeft(2, '0')))
            //    .When(f => f.StartReportYear.HasValue && f.StartReportPeriod.HasValue && f.EndReportYear.HasValue && f.EndReportPeriod.HasValue).WithMessage(DASConst.ReportRangeInvalid);
            #endregion

            #region method rule
            //RuleFor(x => x).Must(CanNotAllEmpty).WithMessage("method rule fail");
            //bool CanNotAllEmpty(FileAddDto addDto)
            //{
            //    bool result = false;
            //    if (addDto.TagIds != null)
            //        result = true;
            //    return result;
            //}
            #endregion
        }
    }    
    public class FileAddManyDtoValidation : AbstractValidator<IList<FileAddDto>>
    {
        public FileAddManyDtoValidation()
        {
            RuleForEach(x => x).SetValidator(new FileAddDtoValidation());
        }
    }
    public class FileUpdateDtoValidation : AbstractValidator<FileUpdateDto>
    {
        public FileUpdateDtoValidation()
        {

        }
    }
    public class FileFilterDtoValidation : AbstractValidator<FileFilterDto>
    {
        public FileFilterDtoValidation()
        {
            RuleFor(x => x.OrderBy).SetValidator(new SortDtoValidation<FileDto>());
        }
    }
}
